<%@page import="com.qububu.ad.dto.TweetInfo"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%
String path = request.getContextPath();
List<TweetInfo> tweetList = (List<TweetInfo>) request.getAttribute("tweets");
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>推文管理</title>
<script type="text/javascript" src="<%=path%>/resource/js/jquery/jquery-1.8.2.js"></script>
<script type="text/javascript" src="<%=path%>/resource/js/honeycombtool.js"></script>
<script type="text/javascript" src="<%=path%>/resource/js/constants.js"></script>
<script type="text/javascript">
	$(function() {
		loadDefaultStyle();
	});
	function loadDefaultStyle() {
		$(".tweet_line:even").addClass("tweet_line_even");
		$(".tweet_line:odd").addClass("tweet_line_odd");
	}
	function hid(id, obj) {
		var objHtmlStr = $(obj).html();
		$(obj).html("");
		var lineNode = $(obj).parent("span").parent(".line_control").parent(".tweet_line");
		var statusHtmlStr = lineNode.find(".line_status").html();
		lineNode.find(".line_status").html("<span class=\"line_status_deleted\">已被标记为删除</span>");
		if (!CHECK.isEmpty(id)) {
			$.ajax({
				url: WEBROOT + "/ad/admin/changeTweetStatus",
				type: "post",
				dataType: "json",
				data: {
					"status": "DELETED",
					"tweetId": id
					},
				success: function(res) {
					if (res.result != 0) {
						lineNode.find(".line_status").html(statusHtmlStr);
						$(obj).html(objHtmlStr);
					}
				}
			});	
		}
	}
	function del(id, obj) {
		var lineNode = $(obj).parent("span").parent(".line_control").parent(".tweet_line");
		lineNode.slideUp("slow");
		if (!CHECK.isEmpty(id)) {
			$.ajax({
				url: WEBROOT + "/ad/admin/deleteTweet",
				type: "post",
				dataType: "json",
				data: {"tweetId": id},
				success: function(res) {
					if (res.result == 0) {
						lineNode.find(".line_control").html("已经彻底删除");
					} else {
						lineNode.slideDown("slow");
					}
				}
			});
		}
	}
</script>
<style type="text/css">
html body{
padding: 0;
margin: 0;
}
.main {
width: 100%;
height: 100%;
font-size: 12px;
color: #333333; 
}
.main .tweet_line, .main .tweet_menu {
width: 100%;
height: 30px;
line-height: 30px;
/* border-bottom: 1px solid #00FFFF; */
}
.main .tweet_menu {
height: 40px;
line-height: 40px;
background: #2E4222; /*313E28,1D2716*/
color: #FFFFFF;
}
.main .tweet_line div, .main .tweet_menu div {
float: left;
margin-left: 5px;
text-align: center;
}
.main .line_title {
width: 200px;
}
.main .line_ip {
width: 160px;
}
.main .line_time {
width: 160px;
}
.main .line_status {
width: 120px;
}
.main .line_status .line_status_deleted {
color: red;
}
.main .line_control {
width: 260px;
}

.main .tweet_line_odd {
background: #EDEDED;
}
.main .tweet_line_even {
background: #AED4F5;
}
</style>
</head>
<body>
	<div class="main">
		<div class="tweet_menu">
			<div class="line_title">标题</div>
			<div class="line_ip">发布时IP</div>
			<div class="line_time">发布时间</div>
			<div class="line_status">状态</div>
			<div class="line_control">操作</div>
			<div style="clear: both;"></div>
		</div>
		<%
		TweetInfo tweet = null;
		for (int i = 0; i < tweetList.size(); i++) {
			tweet = tweetList.get(i);
		%>
		<div class="tweet_line">
			<div class="line_title">
				<a href="<%=path %>/ad/showTweet?t=<%=tweet.getTweetId() %>" target="_blank"><%=tweet.getTitle() %></a>
			</div>
			<div class="line_ip"><%=tweet.getCreateIp() %></div>
			<div class="line_time"><%=tweet.showCreateDttmToDtString() %></div>
			<div class="line_status"><%=tweet.getTweetStatus().name() %></div>
			<div class="line_control">
				<%if (!tweet.getTweetStatus().name().startsWith("DELETE")) {%>
				<span><a href="javascript:void(0)" onclick="hid('<%=tweet.getTweetId()%>', this)">删除</a></span>
				<%} %>
				<span><a href="javascript:void(0)" onclick="del('<%=tweet.getTweetId()%>', this)">彻底删除</a></span>
			</div>
			<div style="clear: both;"></div>
		</div>
		<%} %>
	</div>
</body>
</html>